﻿// <copyright file="DetailsPage.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2010-08-20</date>
// <summary>DetailsPage code behind</summary>

namespace WindowsPhoneListApplication
{
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;

    /// <summary>
    /// Windows Phone Details page
    /// </summary>
    public partial class DetailsPage : PhoneApplicationPage
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the DetailsPage class
        /// </summary>
        public DetailsPage()
        {
            InitializeComponent();
        }
        #endregion

        #region Methods

        /// <summary>
        /// When page is navigated to, set data context to selected item in list
        /// </summary>
        /// <param name="e">the navigation event arguments</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string selectedIndex = string.Empty;
            if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
            {
                int index = int.Parse(selectedIndex);
                DataContext = App.ViewModel.Items[index];
            }
        }
        #endregion
    }
}
